<?php
session_start();
header('Content-type:text/html;charset=utf-8');
header('Content-type: application/json');
header('Access-Control-Allow-Origin:*');
include_once './dbConfig.php';
include_once './public.php';


if (isset($_REQUEST['user'])) {
    $username = $_REQUEST['user'];
} else {
    $msg = ['msg' => '请登录', 'status' => 0];
    reponseEvent($msg);
}

if ($_GET) {
    if (isset($_GET['getType']) && $_GET['getType'] == 'shopCar') {
        $select = 'select p.*,s.num,s.checked,s.id as shop_id from lgz_product as p JOIN lgz_shop_car as s on s.pro_id = p.id where s.status=1 and s.username="' . $username . '"';
        $results = selectEvent($select);
        reponseEvent($results);
    }
}

if ($_POST) {
    if (isset($_POST['postType']) && $_POST['postType'] == 'changeNum') {
        $id = $_POST['id'];
        $num = $_POST['num'];
        $update = 'update lgz_shop_car set num =' . $num . ' where id=' . $id;
        if ($link->query($update)) {
            $msg = ['msg' => '修改成功!', 'status' => 1];
        } else {
            $msg = ['msg' => '修改失败!', 'status' => 0];
        }
        reponseEvent($msg);
    }
    if (isset($_POST['postType']) && $_POST['postType'] == 'commit') {
        $id = $_POST['id'];
        $check = $_POST['check'];
        $update = 'UPDATE `lgz_shop_car` SET `checked` = "' . $check . '" WHERE id = "' . $id . '"';
        if ($link->query($update)) {
            $msg = ['msg' => '添加成功！', 'status' => 1];
        } else {
            $msg = ['msg' => '添加失败！', 'status' => 0];
        }
        reponseEvent($msg);
    }
    if (isset($_POST['postType']) && $_POST['postType'] == 'del') {
        $id = $_POST['id'];
        $update = 'UPDATE `lgz_shop_car` SET `status` = 0,`num` = 0 WHERE id = "' . $id . '"';
        if ($link->query($update)) {
            $msg = ['msg' => '删除成功！', 'status' => 1];
        } else {
            $msg = ['msg' => '删除失败！', 'status' => 0];
        }
        reponseEvent($msg);
    }
}


